package edu.bw.service.impl;


import edu.bw.service.UserService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * @PostConstruct:标注在初始化方法,当构造方法执行后,执行初始化方法,相当于init-method属性
 * @PreDestroy: 标注在销毁方法上,如果Bean是单例的话,当Spring容器关闭的时候,会调用Bean的销毁方法,相当于destroy-method属性
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) //指定Bean的范围
public class UserServiceImpl05 implements UserService {
    public UserServiceImpl05() {
        System.out.println(this + "构造方法被调用");
    }

    @PostConstruct
    public void init() {
        System.out.println(this + "初始化");
    }

    @PreDestroy
    public void destroy() {
        System.out.println(this + "被销毁");
    }

}
